import request from "@/utils/http";

/**
 * 添加商品到购物车
 * @param {String} skuId 商品的skuid
 * @param {Number} count 购买的数量
 */
export const addCartAPI = (skuId, count) => {
    return request({
        url: "/member/cart",
        method: "post",
        data: { skuId, count },
    });
};

/**
 * 请求列表
 */
export const getCartsAPI = () => {
    return request({
        url: "/member/cart",
    });
};

/**
 * 根据id 来切换选中
 * @param {String } skuId SKUid
 * @param {Object}  selected 选中, count 购买的数量  可选
 */
export const updateCartAPI = (skuId, data) => {
    return request({
        url: `/member/cart/${skuId}`,
        method: "PUT",
        data: data,
    });
};

/**
* 购物车全选/取消全选
* @param {*} selected  选中状态
*/
export const memberCartSelected = (selected) => {
    return request({
        url: `/member/cart/selected`,
        method: "PUT",
        data: { selected },
    });
};

/**
 * 根据 skuid来删除购物车数据
 * @param {Array<String>} ids 要删除商品的skuid集合
 * @returns 
 */
export const delCartByIdAPI = (ids) => {
    return request({
      url: `/member/cart`,
      method: "delete",
      data: { ids },
    });
  };